
<?php
//模块插件类
//插件功能类，由系统调用，实现具体功能。
defined('BY_JYA') or exit('error');
class core_jy_weishop extends plugin{
	public function __construct($name){
		global $_RQ;
		parent::__construct($name);
	}
	public function qr_scan($qr){
		$senddata['touser'] = $qr['openid'];
		$senddata['msgtype'] = 'text';
		$data=json_decode($qr['data'],true);
		if(!empty($qr['openid'])){
			$openid = $qr['openid'];
		}else{
			$text = '认证服务号才能使用微信客服哦！';
			$senddata['text']['content'] = $text;
			$res = cfc('account')->sendCustomNotice($senddata);
			return null;
		}
		$kf_account = $data['kf_account'];
		if(!$kf_account){
			$shopset=$this->plugin_setting('shopset');
			$kf_account = $shopset['kf_account'];
		}
		$content = cfc('kefu')->setkfsession($kf_account,$openid);
		if($content['errcode'] != 0){
			$text = cfc('kefu')->error_code($content['errcode']);
			$senddata['text']['content'] = $text;
			$res = cfc('account')->sendCustomNotice($senddata);
			return null;
		}
		$text =$shopset['kf_welcome']?:'您好！我是客服，有任何问题，请直接发信息咨询！';
		$senddata['text']['content'] = $text;
		$senddata['customservice']=$kf_account;
		$res = cfc('account')->sendCustomNotice($senddata);
		return null;
	}
	public function array_sort($arr , $keys , $type = 'asc') {
        $keysvalue = $new_array = array();
        foreach ($arr as $k => $v) {
            $keysvalue[$k] = $v[$keys];
        }
        if ($type == 'asc') {
            asort($keysvalue);
        } else {
            arsort($keysvalue);
        }
        reset($keysvalue);
        foreach ($keysvalue as $k => $v) {
            $new_array[$k] = $arr[$k];
        }
        return $new_array;
    }	
}
require ROOT_D . '/addons/jy_weishop/customfunc.php';
?>
